<script setup>
  //按需导入ref,reactive
  import { ref,reactive } from 'vue';
  //图片路径
  const imgs = ['../public/pic/cat.jpg',
    '../public/pic/logo.png',
    '../public/pic/R-C.jpg'
  ];
  alert(imgs.length);
  const i = ref(1);
  const prev = () => {
    (i.value === 0) ? i.value = 2 : i.value--;
  }
  const next = () => {
    (i.value === 2) ? i.value = 0 : i.value++;
  }
</script>

<template>
  <div class="banner">
    <img :src="imgs[i]"alt="图片加载失败">
    <div class="ctrl">
      <a 
      href="javascript:;" 
      class="button prev"
      @click="prev">
        &lt;
      </a>
      <a href="javascript:;" 
        class="button next"
        @click="next">
        &gt;
      </a>
    </div>
  </div>
</template>

<style scoped>
  *{
    margin: 0;
  }
  a{
    text-decoration: none;
    color: white;
  }
  img{
    width: 1200px;
    height: 337px;
  }
  .banner{
    position: relative;
    width: 1200px;
    height: 337px;
    margin: 150px auto;
  }
  .banner .ctrl .button{
    position: absolute;
    top: 50%;
    width: 30px;
    height: 30px;
    margin-top: -15px;
    font-size: 14px;
    line-height: 30px;
    text-align: center;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.3);
  }
  .banner .ctrl .button.prev{
    left: 15px;
  }
  .banner .ctrl .button.next{
    right: 15px;
  }
</style>